package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark20Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class Mark20 extends BaseMark {

    LayoutWatermark20Binding binding;

    public Mark20(@NonNull Context context) {
        super(context);
    }

    public Mark20(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark20(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark20Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark20Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
        if (type == 0) {
            hideView(binding.binding10, binding.binding12, binding.binding14);
        }
    }

    @Override
    public void update() {
        setText(binding.binding1, "title20", binding.title);
        setText(binding.binding3, "time20", binding.binding2);
        setTime(binding.binding3, new SimpleDateFormat("HH:mm"));
        if (!setTime(binding.binding4, new SimpleDateFormat("yyyy-MM-dd"))) {
            binding.binding4.setText("2023-03-09");
        }
        if (!setWeek(binding.binding5, 1)) {
            binding.binding5.setText("周四");
        }
        setText(binding.binding7, "didian20", binding.binding6);
        setText(binding.binding9, "lou20", binding.binding8);
        setText(binding.binding11, "job20", binding.binding10);
        setText(binding.binding13, "danwei20", binding.binding12);
        setText(binding.binding15, "beizhu20", binding.binding14);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title20", "标题"));
        list.add(new EditItem("time20", "时间", true));
        list.add(new EditItem("didian20", "地址"));
        list.add(new EditItem("lou20", "单元楼"));
        list.add(new EditItem("job20", "工作内容"));
        list.add(new EditItem("danwei20", "单位"));
        list.add(new EditItem("beizhu20", "备注"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding3, new SimpleDateFormat("HH:mm"));
            setTime(binding.binding4, new SimpleDateFormat("yyyy-MM-dd"));
            setWeek(binding.binding5, 1);
        } else {
            super.onValueChange(item);
        }
    }
}
